const express = require("express");
const morgan = require("morgan");
const cors = require("cors");
const router = require("./router");
const errorHandler = require("./middleware/error-handler");
require("./model");
const app = express();

// 配置常用中间件
app.use(morgan("dev"));
app.use(express.json());

app.use(cors());
// app.use(express.urlencoded());

const PORT = process.env.PORT || 3000;

// 挂载路由
app.use("/api", router);

app.use(errorHandler());

app.listen(PORT, () => {
  console.log(`Server is running at http://127.0.0.1:${PORT}`);
});
